//在某个元素后面插入
function insertAfter(newObj, oldObj) {
    // console.log( oldObj)
    if (oldObj == oldObj.parentNode.lastChild) {
        oldObj.parentNode.appendChild(newObj)
    } else {
        oldObj.parentNode.insertBefore(newObj, oldObj.nextElementSibling)
    }
}

function clearHint(el) {
    // console.log(el)
    if(el.parentNode.nextElementSibling){
        if (el.parentNode.nextElementSibling.flag === "did"){
            el.parentNode.nextElementSibling.remove();
            el.parentNode.style.borderColor = "#DCDFE6"
        }
     
    }
    
}
function isTrue(elid,isChoose,str,...args) {
    var  el=$("#"+elid)
    var text = el.val().trim()
    const isWhat = {
        isEmpty:function(){        
           if(text.length===0) return false
            else return true
        },
        isLength:function(){
            let reg =/[0-9]+/g
           let arrStr =  str.split(reg)
           str = arrStr[0]+args[0]+arrStr[1]+args[1]+arrStr[2]
        //    console.log(str)
            // str = ""
            if(text.length<args[0]) return false
            else return true
        },
        isPhoneNum:function(){
            let regNum= /^1[3456789]\d{9}$/;
            // console.log(regNum.test(el.val()))
           return regNum.test(el.val())
        },
        isAffirm:function(){
            if(el.val() === $("#"+args[0]).val()) return true
            else return false
        },
        isIdNum:function(){
            let regIdNum=/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
            return regIdNum.test(el.val())
        }
    }
    if(!isWhat[isChoose]()){
        let hint = document.createElement("o");
        // console.log(hint)
        hint.flag = "did"
        hint.innerText = str
        hint.style.position = "absolute"
        hint.style.fontSize = "12px"
        hint.style.color = "red"
        if (el[0].parentNode.nextElementSibling === null||el[0].parentNode.nextElementSibling.flag != "did") {
            insertAfter(hint, el[0].parentNode);
            el[0].parentNode.style.borderColor = "red"
        }
        return false
}else{
    clearHint(el[0])
    return true
}
}
